﻿#pragma once  
#include "PubFunc.h"
//
 
#define DEF_TEXT_FRAME_COLOR			RGB(255,255,255)				//默认颜色;
#define DEF_TEXT_COLOR					RGB(10,10,10)					//默认颜色;
#define TOOLTIP_ID						100								//提示 ID;
 
//
class CPngButton : public CButton
{
public:
	CPngButton();
	virtual ~CPngButton();
public:
	// 初始化;
    void Init(UINT nImg, int nPartNum, UINT nBtnType = BTN_TYPE_NORMAL, UINT uWidth = 0, UINT uHeight = 0);
	//设置颜色;
	bool SetTextColor(COLORREF crTextColor, COLORREF crTextFrameColor = DEF_TEXT_FRAME_COLOR, bool bShowFrame = false);
	//设置提示;
	void SetToolTips(LPCTSTR pszTips);
	//设置鼠标形状;
	void SetCursorType(HCURSOR hCursor);
	//设置字体大小及类型;
	void SetFontType(int fontSize, CString fontType);
protected:
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg LRESULT OnMouseHOver(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnPaint();
	DECLARE_MESSAGE_MAP()
 
protected:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual void PreSubclassWindow();
	virtual BOOL PreTranslateMessage(MSG * pMsg);
	bool ShowImage(CDC* pDC, Image* pImage, UINT nState);
	void PaintParent();
	Image *ImageFromResource(HINSTANCE hInstance, UINT uImgID, LPCTSTR lpType);
	void UpdateToolTip();
	void DrawTextString(CDC * pDC, LPCTSTR pszString, COLORREF crText, COLORREF crFrame, LPRECT lpRect);
	void DrawTextString(CDC * pDC, LPCTSTR pszString, COLORREF crText, COLORREF crFrame, int nXPos, int nYPos);
 
private:
	int m_nImgPart;									//载入的图片是几块;
	UINT			m_nState;						//控件状态;
	UINT			m_nBtnType;						//按钮类型;
	BOOL			m_bMenuOn;						//是否按下;
	BOOL			m_bTracked;						//是否移动;
	BOOL			m_bShowTextFrame;				//是否显示艺术字体;
	COLORREF		m_crTextColor;					//字体颜色;
	COLORREF		m_crTextFrameColor;				//艺术字体边缘颜色;
	CString			m_strTips;						//提示;
	HCURSOR			m_cursor;						//光标;
	CToolTipCtrl	m_ToolTip;						//提示控件;
	Image*			m_pImage;						//背景图片;
	CFont			m_font;							//字体;
    UINT            m_width;                        //按钮宽;
    UINT            m_height;                       //按钮高;
};